package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "服务端订单接口")
@Slf4j
@RequestMapping("/admin/order")
@RestController("adminOrderController")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     * @param pageQueryDTO
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO pageQueryDTO){
        log.info("订单搜索{}",pageQueryDTO);
        PageResult pageResult = orderService.pageQuery(pageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getStatusCount(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO orderStatisticsVO = orderService.getStatusCount();
        return Result.success(orderStatisticsVO);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderById(@PathVariable Long id){
        log.info("查询订单详情{}",id);
        OrderVO orderVO  = orderService.getOrderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result updateReceive(@RequestBody OrdersDTO ordersDTO){
        log.info("接单{}",ordersDTO.getId());
        orderService.updateStatus(ordersDTO);
        return Result.success();
    }

    @ApiOperation("派送")
    @PutMapping("/delivery/{id}")
    public Result updateSend(@PathVariable Long id){
        log.info("派送{}",id);
        OrdersDTO ordersDTO = new OrdersDTO();
        ordersDTO.setId(id);
        orderService.updateStatus(ordersDTO);
        return Result.success();
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result updateOver(@PathVariable Long id){
        log.info("完成订单id{}",id);
        OrdersDTO ordersDTO = new OrdersDTO();
        ordersDTO.setId(id);

        orderService.updateStatus(ordersDTO);
        return Result.success();
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单{}",ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }




}
